package com.st.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.st.domain.StStudyRecords;
import com.st.service.IStStudyRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 已购买产品学习记录Controller
 * 
 * @author zhw
 * @date 2024-10-24
 */
@RestController
@RequestMapping("/st/studyRecords")
public class StStudyRecordsController extends BaseController
{
    @Autowired
    private IStStudyRecordsService stStudyRecordsService;

    /**
     * 查询已购买产品学习记录列表
     */
    @PreAuthorize("@ss.hasPermi('st:studyRecords:list')")
    @GetMapping("/list")
    public TableDataInfo list(StStudyRecords stStudyRecords)
    {
        startPage();
        List<StStudyRecords> list = stStudyRecordsService.selectStStudyRecordsList(stStudyRecords);
        return getDataTable(list);
    }

    /**
     * 导出已购买产品学习记录列表
     */
    @PreAuthorize("@ss.hasPermi('st:studyRecords:export')")
    @Log(title = "已购买产品学习记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StStudyRecords stStudyRecords)
    {
        List<StStudyRecords> list = stStudyRecordsService.selectStStudyRecordsList(stStudyRecords);
        ExcelUtil<StStudyRecords> util = new ExcelUtil<StStudyRecords>(StStudyRecords.class);
        util.exportExcel(response, list, "已购买产品学习记录数据");
    }

    /**
     * 获取已购买产品学习记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('st:studyRecords:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(stStudyRecordsService.selectStStudyRecordsById(id));
    }

    /**
     * 新增已购买产品学习记录
     */
    @PreAuthorize("@ss.hasPermi('st:studyRecords:add')")
    @Log(title = "已购买产品学习记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StStudyRecords stStudyRecords)
    {
        return toAjax(stStudyRecordsService.insertStStudyRecords(stStudyRecords));
    }

    /**
     * 修改已购买产品学习记录
     */
    @PreAuthorize("@ss.hasPermi('st:studyRecords:edit')")
    @Log(title = "已购买产品学习记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StStudyRecords stStudyRecords)
    {
        return toAjax(stStudyRecordsService.updateStStudyRecords(stStudyRecords));
    }

    /**
     * 删除已购买产品学习记录
     */
    @PreAuthorize("@ss.hasPermi('st:studyRecords:remove')")
    @Log(title = "已购买产品学习记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(stStudyRecordsService.deleteStStudyRecordsByIds(ids));
    }
}
